

class Stack(object):
    def __init__(self):
        self.stack=[]
    def pop(self):
        if self.stack:
            return self.stack.pop()
        else:
            return None
        
    def push(self,obj):
        self.stack.append(obj)
        
    def peek(self):
        if self.stack:
            return self.stack[-1]
        else:
            return None
    def length(self):
        return len(self.stack)
            
def _calculate(sign_stack,num_stack):
    sub_formula=[]
    sub_formula.append(num_stack.pop())
    sub_formula.append(sign_stack.pop())
    sub_formula.append(num_stack.pop())
    sub_formula.reverse()
    sub_f=''.join(sub_formula)
    r=eval(sub_f)
    num_stack.push(str(r))
    return sign_stack,num_stack

def calculate(formula):
    '''2*10+5*6'''
    result=0
    sign_stack=Stack()
    num_stack=Stack()
    sign_list=['+','-','*','/',]
    sign_weight={'+':1,
                 '-':1,
                 '*':2,
                 '/':2}
    i=0
    while i<len(formula):
        if formula[i] in sign_list:
            if sign_stack.length() and sign_weight[formula[i]]<=sign_weight[sign_stack.peek()]:
                sign_stack,num_stack=_calculate(sign_stack,num_stack)
            sign_stack.push(formula[i])
            i+=1
        else:
            sub_num=''
            while formula[i] not in sign_list:
                sub_num+=formula[i]
                i+=1
                if i>=len(formula):
                    break;
            num_stack.push(sub_num)
    while sign_stack.stack:
        sign_stack,num_stack=_calculate(sign_stack,num_stack)
    #print sign_stack.stack
    print formula,'=',num_stack.stack.pop()

calculate('26*10+5*100-60')






